package io.renren.controller;

import com.gexin.rp.sdk.base.IPushResult;
import com.gexin.rp.sdk.base.impl.AppMessage;
import com.gexin.rp.sdk.base.impl.SingleMessage;
import com.gexin.rp.sdk.base.impl.Target;
import com.gexin.rp.sdk.http.IGtPush;
import com.gexin.rp.sdk.template.LinkTemplate;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author rdawnx
 * @package_name io.renren.controller
 * @class_name AppPush.java
 * @author_email rdawnxhi@163.com
 * @JDK_version 1.8
 * @create_on 2019/07/29 20:14
 */
public class AppPush {
    //定义常量, appId、appKey、masterSecret 采用本文档 "第二步 获取访问凭证 "中获得的应用配置
//    private static String appId = "r0rxy3ndJl7K1yOatHukl";
//    private static String appKey = "UDBX4WvzL9AsFvkVh3TwE6";
//    private static String masterSecret = "JucwPia7n89lbEApCs9nR5";
    private static String appId = "eoO2THVmskAd8VQtlL1S1";
    private static String appKey = "cQ8iYpW0y36eRYA0xgAuG7";
    private static String masterSecret = "sKsiaWcg9g8x78yR5FAgO2";

    private static String url = "http://sdk.open.api.igexin.com/apiex.htm";

    public static void main(String[] args) throws IOException {

        IGtPush push = new IGtPush(url, appKey, masterSecret);

        // 定义"点击链接打开通知模板"，并设置标题、内容、链接
        LinkTemplate template = new LinkTemplate();
        template.setAppId(appId);
        template.setAppkey(appKey);
        template.setTitle("请填写通知标题");
        template.setText("请填写通知内容");
        template.setUrl("http://getui.com");

        List<String> appIds = new ArrayList<String>();
        appIds.add(appId);

        // 定义"AppMessage"类型消息对象，设置消息内容模板、发送的目标App列表、是否支持离线发送、以及离线消息有效期(单位毫秒)
        AppMessage message = new AppMessage();
        message.setData(template);
        message.setAppIdList(appIds);
        message.setOffline(true);
        message.setOfflineExpireTime(1000 * 600);

        SingleMessage message1 = new SingleMessage();
        message1.setData(template);

        IPushResult ret = push.pushMessageToApp(message);
        System.out.println(ret.getResponse().toString());

        Target target = new Target();
        target.setAppId(appId);
        target.setClientId("436c773ddccedb25b656b2e34e48c460");
//        IPushResult ret1 = push.pushMessageToSingle(message1, target);
//        System.out.println(ret1.getResponse().toString());
    }
}
